package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallOrderCouponModel;
import com.mallcloud.mall.mall.api.entity.vo.MallOrderCouponVO;
import com.mallcloud.mall.mall.service.MallOrderCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-券订单")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/orderCoupon")
public class MallOrderCouponController {
	private final MallOrderCouponService orderCouponService;

    @ApiOperation("分页")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupon_view')")
    public R<IPage<MallOrderCouponVO>> page(Page page, MallOrderCouponModel dto) {
        return R.ok(orderCouponService.pageOrderCoupon(page, dto));
    }

    @ApiOperation("列表")
    @GetMapping("/list")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupon_view')")
    public R<List<MallOrderCouponVO>> list(MallOrderCouponModel dto) {
        return R.ok(orderCouponService.listOrderCoupon(dto));
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupon_view')")
    public R<MallOrderCouponModel> getById(@PathVariable("id") String id) {
        return R.ok(orderCouponService.getById(id));
    }

    @ApiOperation("新增")
	@PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupon_add')")
    public R<Boolean> save(@RequestBody MallOrderCouponModel dto) {
		return R.ok(orderCouponService.save(dto));
    }

    @ApiOperation("修改")
	@PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupon_edit')")
    public R<Boolean> updateById(@RequestBody MallOrderCouponModel dto) {
        return R.ok(orderCouponService.updateById(dto));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupon_del')")
    public R<Boolean> removeById(@PathVariable Long id) {
        return R.ok(orderCouponService.removeById(id));
    }

	@ApiOperation("导出")
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupon_export')")
    public List<MallOrderCouponModel> export(MallOrderCouponModel dto) {
        return orderCouponService.list(Wrappers.query(dto));
    }

	@ApiOperation("补偿")
	@PostMapping("/compensate")
	@PreAuthorize("@pms.hasPermission('mall_ordercoupon_compensate')")
	public R<Boolean> compensate(@RequestBody List<Long> ids) {
		return R.ok(orderCouponService.compensate(ids));
	}
}
